package com.zainzhou.controller;

import com.zainzhou.handler.UserHandler;
import com.zainzhou.pojo.request.CreateUserRequest;
import com.zainzhou.pojo.request.LoginRequest;
import com.zainzhou.pojo.request.UpdateUserRequest;
import com.zainzhou.pojo.response.LoginResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : 周振宇
 * Created on 2024/06/19 10:55
 **/
@RestController
public class UserController {
    @Resource
    private UserHandler userHandler;

    @PostMapping("/api/user/login")
    public LoginResponse login(@RequestBody @Validated LoginRequest loginRequest) {
        return userHandler.login(loginRequest);
    }

    @PutMapping("/api/user/update")
    public int updateUser(@RequestBody @Validated UpdateUserRequest updateUserRequest) {
        return userHandler.updateUser(updateUserRequest);
    }

    @PostMapping("/api/user/create")
    public String createUser(@RequestBody @Validated CreateUserRequest createUserRequest) {
        return userHandler.createUser(createUserRequest);
    }

    @DeleteMapping("/api/user/delete")
    public int deleteUser(@RequestParam String id) {
        return userHandler.deleteUser(id);
    }
}
